<html>
  <head>
    <script>

var apiHandle;
var newTabPageHandle;

var onMostVisitedChangedCalls = 0;
var mostVisitedItemsCount = 0;
var firstMostVisitedItemId = 0;
var onFocusChangedCalls = 0;
var isFocused = false;
var onThemeChangedCalls = 0;

function getApiHandle() {
  if (window.chrome && window.chrome.embeddedSearch &&
      window.chrome.embeddedSearch.searchBox)
    return window.chrome.embeddedSearch.searchBox;
  return null;
}

function getNewTabPageHandle() {
  if (window.chrome && window.chrome.embeddedSearch &&
      window.chrome.embeddedSearch.newTabPage)
    return window.chrome.embeddedSearch.newTabPage;
  return null;
}

function handleMostVisitedChange() {
  onMostVisitedChangedCalls++;
  var items = newTabPageHandle.mostVisited;
  if (items) {
    mostVisitedItemsCount = items.length;
    firstMostVisitedItemId = items[0] ? items[0].rid : 0;
  }
}

function handleFocusChange() {
  onFocusChangedCalls++;
  isFocused = apiHandle.isFocused;
}

function handleThemeChange() {
  onThemeChangedCalls++;
}

function setUp() {
  apiHandle = getApiHandle();
  if (!apiHandle)
    return;

  apiHandle.onfocuschange = handleFocusChange;

  newTabPageHandle = getNewTabPageHandle();
  newTabPageHandle.onmostvisitedchange = handleMostVisitedChange;
  newTabPageHandle.onthemechange = handleThemeChange;
  if (newTabPageHandle.mostVisited && newTabPageHandle.mostVisited.length) {
    handleMostVisitedChange();
  }
  handleFocusChange();
}

setUp();

    </script>

    <meta name="referrer" content="origin" />

  </head>
  <body>
    <h1>Instant</h1>
  </body>
</html>
